import axios from 'axios'
import store from '@/store'

const instance = axios.create({
  baseURL: 'http://big-event-vue-api-t.itheima.net'
})

// 请求拦截器
instance.interceptors.request.use(
  config => {
    // config: 请求报文
    config.headers.Authorization = `${store.state.user.token}`
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
// 响应拦截器
instance.interceptors.response.use(
  response => {
    // response: 响应报文
    return response.data
  },
  error => {
    return Promise.reject(error)
  }
)

export default instance
